package mercurialpractice
class ViewBillController {
    def index = {
        redirect(action: "viewbill")
    }

    def viewbill = {
        def bills = Bill.list().last()
        def cherryP=5.95*bills.cherry
        def curlyMP= 6*bills.curlyMaple
        def genuineMP= 9.6*bills.genuineMahogany
        def wengeP= 22.35*bills.wenge
        def whiteOP= 6.7*bills.whiteOak
        def sawdustP= 1.5*bills.sawdust
        def totalP=cherryP+curlyMP+genuineMP+wengeP+whiteOP+sawdustP
        def ship = [Time(bills.cherry)*0.5, Time(bills.curlyMaple)*1.5,
            Time(bills.genuineMahogany)*3.0,Time(bills.wenge)*5.0,Time(bills.whiteOak)*2.4]
        def maxim=max(ship)

        [bills:bills, cherryP:cherryP, curlyMP:curlyMP, genuineMP:genuineMP, wengeP:wengeP, whiteOP:whiteOP, sawdustP:sawdustP, totalP:totalP, maxim:maxim]

    }

    def max={ ship ->
        float maximo = 0
        for(i in 0..4){
            if(maximo<ship[i]){
                maximo=ship[i]
            }
        }
        return maximo
    }

    def Time={t->
        if(t>0){
            switch(t){
            case 1..100:
                t=1
                break;
            case 101..200:
                t=2
                break
            case 201..300:
                t=3
                break
            case 301..400:
                t=4
                break
            case 401..500:
                t=5
            case 500..1000:
                t=5.5
                break
            default:
                t="default"
                break 
                return t
            }
        }else{return 0}
    }
}